﻿CREATE VIEW dbo.VIEW_SEARCH_INVOICE_OUT
AS
SELECT        dbo.INVOICE_OUT.ID, dbo.INVOICE_OUT.NUMBER, dbo.INVOICE_OUT.DATE, dbo.INVOICE_OUT.SUM, dbo.CONTRACT.NUMBER AS CONTRACT_NUM, 
                         dbo.NSI_CURRENCY.SHORT_NAME AS NSI_CURRENCY_SHORT_NAME, dbo.NSI_ORGANIZATION.SHORT_NAME AS NSI_ORGANIZATION_SHORT_NAME, 
                         dbo.NSI_TYPE_OF_ACTIVITY.NAME AS NSI_TYPE_OF_ACTIVITY_NAME, dbo.INVOICE_OUT.PID, dbo.INVOICE_OUT.STATE, 
                         dbo.INVOICE_OUT.NSI_ORGANIZATION_ID
FROM            dbo.NSI_ORGANIZATION RIGHT OUTER JOIN
                         dbo.INVOICE_OUT ON dbo.NSI_ORGANIZATION.ID = dbo.INVOICE_OUT.NSI_ORGANIZATION_ID LEFT OUTER JOIN
                         dbo.CONTRACT ON dbo.INVOICE_OUT.PID = dbo.CONTRACT.PID LEFT OUTER JOIN
                         dbo.NSI_TYPE_OF_ACTIVITY ON dbo.CONTRACT.NSI_TYPE_OF_ACTIVITY_ID = dbo.NSI_TYPE_OF_ACTIVITY.ID LEFT OUTER JOIN
                         dbo.NSI_CURRENCY ON dbo.INVOICE_OUT.NSI_CURRENCY_ID = dbo.NSI_CURRENCY.ID